<?php

	//PHP函数-获取网站域名地址
	/**
	 * 获得当前网站的域名地址
	 *
	 * @param      boolean $isport 是否在返回值中添加端口信息
	 * @return     string
	 */
/*function gethost($isport = false) {
     $scheme = (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
     if(!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
         $t = strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ':');
         if($t > 0) {
             $host = substr($_SERVER['HTTP_X_FORWARDED_HOST'], 0, $t);
             $port = substr($_SERVER['HTTP_X_FORWARDED_HOST'], $t+1);
         } else {
         $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
         }
     } else if(!empty($_SERVER['HTTP_HOST'])) {
         $t = strpos($_SERVER['HTTP_HOST'], ':');
         if($t >0) {
             $host = substr($_SERVER['HTTP_HOST'], 0, $t);
             $port = substr($_SERVER['HTTP_HOST'], $t+1);
         } else {
             $host = $_SERVER['HTTP_HOST'];
         }
     } else if(!empty($_SERVER['SERVER_NAME'])) {
         $host = $_SERVER['SERVER_NAME'];
     }
     if(empty($port)) {
         $port = $_SERVER['SERVER_PORT'];
     }
     if($isport) {
         return $scheme . $host . ':' . $port;
     } else {
         return $scheme . $host;
     }
}*/

//文章来源：http://www.lvyaozu.com/article.asp?id=28

//+++++++++++++++++++++++++方法二++++++++++++++++++++++++++++++++

function PMA_getenv($var_name) {
    if (isset($_SERVER[$var_name])) {
        return $_SERVER[$var_name];
    } elseif (isset($_ENV[$var_name])) {
        return $_ENV[$var_name];
    } elseif (getenv($var_name)) {
        return getenv($var_name);
    } elseif (function_exists('apache_getenv')
     && apache_getenv($var_name, true)) {
        return apache_getenv($var_name, true);
    }

    return '';
}
if (empty($HTTP_HOST)) {
    if (PMA_getenv('HTTP_HOST')) {
        $HTTP_HOST = PMA_getenv('HTTP_HOST');
    } else {
        $HTTP_HOST = '';
    }
}
echo htmlspecialchars($HTTP_HOST); // 结果如：www.cnshuwu.com

//方法二来自phpmyadmin

?>